//
//  DengJiViewController.m
//  KuWoCan
//
//  Created by LiBenCan on 17/6/16.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "DengJiViewController.h"
#import "TopDJView.h"
#import "NWLoginRequest.h"
//#import "AFNetworking.h"
@interface DengJiViewController ()<UIWebViewDelegate,UITableViewDelegate,UIScrollViewDelegate>
@property (nonatomic,strong)NSDictionary *dataDic;
@property (nonatomic,strong)UIWebView *webView;
@property (nonatomic,strong)UIView *BaseView;
@property (nonatomic,assign)NSInteger pianyiY;
@end

@implementation DengJiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _pianyiY = 0;
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    _dataDic = [[NSDictionary alloc]init];
    [self addRequest];
    
}
-(void)addRequest
{

    [SVProgressHUD show];

    [NWLoginRequest PostrequestUrl:[NSString stringWithFormat:@"%@/jeesite/interface/appUserinfo/findCustomerLevel",baseUrlMe] Dic:@{@"userId":[Singleton shareInstance].userId} completion:^(NSDictionary *responseDic) {
        if ([responseDic[@"success"] boolValue]) {
            if (![responseDic[@"data"] isEqual:@""]) {
                [self addtopView:responseDic[@"data"]];
            }else
            {
                [self addtopView:nil];
            }
            
        }else
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败"];
        }
        [self addWebViewRequest];
    }];
    
}
-(void)addWebViewRequest
{
    [NWLoginRequest PostrequestUrl:[NSString stringWithFormat:@"%@/jeesite/interface/appUserinfo/findLevelMessage",baseUrlMe] Dic:nil completion:^(NSDictionary *responseDic) {
        if ([responseDic[@"success"] boolValue]) {
            _dataDic = responseDic[@"data"];
            [self addWebView];
        }else
        {
            [SVProgressHUD showErrorWithStatus:@"请求失败"];
        }
            [SVProgressHUD dismiss];
    }];
}
-(void)addtopView:(NSDictionary *)dic
{
    _BaseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENW, 220*screenW_6)];
    [self.view addSubview:_BaseView];
    TopDJView *topMeView = [[TopDJView alloc]initWithFrame:CGRectMake(0,0, SCREENW,220*screenW_6)];
    [topMeView addTopViewDataDic:dic];
    [topMeView.leftBTn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    [_BaseView addSubview:topMeView];
    
}
-(void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)addWebView
{
    _webView = [[UIWebView alloc]initWithFrame:CGRectMake(0,220*screenW_6,SCREENW, SCREENH-220*screenW_6)];
    [self.view addSubview:_webView];
    _webView.backgroundColor = [UIColor whiteColor];
    _webView.delegate = self;
//    _webView.scrollView.delegate = self; 
    [_webView loadHTMLString:_dataDic[@"contents"]?_dataDic[@"contents"]:@"" baseURL:nil];
    [self.view bringSubviewToFront:_webView];
    [_webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
    
    [_webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
}
//-(void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    NSLog(@"======%f",scrollView.contentOffset.y);
//    if (scrollView.contentOffset.y>0 && _pianyiY>-265*screenW_6)
//    {
//         NSLog(@"_pianyiY111======%ld",_pianyiY);
//        _pianyiY = _pianyiY -scrollView.contentOffset.y;
//        _BaseView.frame = CGRectMake(0,_pianyiY, SCREENW, 265*screenW_6);
//        _webView.frame =CGRectMake(0,CGRectGetMaxY(_BaseView.frame),SCREENW,SCREENH-265*screenW_6+scrollView.contentOffset.y);
//        if (_pianyiY<=-265*screenW_6) {
//             _webView.scrollView.contentOffset = CGPointMake(0, 0);
//             _webView.frame =CGRectMake(0,0,SCREENW,SCREENH);
//        }
//       
//    }
//    else if(scrollView.contentOffset.y<=0 && _pianyiY< 265*screenW_6){
//          NSLog(@"_pianyiY2222======%ld",_pianyiY);
//        _pianyiY = _pianyiY -scrollView.contentOffset.y;
//        if (_pianyiY>=0) {
//            _pianyiY = 0;
//        }else if(_pianyiY<-265*screenW_6)
//        {
//            _pianyiY = -265*screenW_6;
//        }
//        _BaseView.frame = CGRectMake(0,_pianyiY, SCREENW, 265*screenW_6);
//        _webView.frame =CGRectMake(0,CGRectGetMaxY(_BaseView.frame),SCREENW,SCREENH-_BaseView.frame.size.height-_pianyiY);
//       
//    }
//}
//
@end
